const mongoose = require('mongoose');
const {Schema, model} = mongoose;

const trackdataSchema = new Schema({
        cardId: { type: String },
        acc:     { type: Number },
        acc_x:     { type: Number },
        acc_y:     { type: Number },
        acc_z:     { type: Number },
        ang_x:     { type: Number },
        ang_y:     { type: Number },
        ang_z:     { type: Number },
        card_type:     { type: Number },
        hang_height:     { type: Number },
        hang_time:     { type: Number },
        jump:     { type: Number },
        speed:     { type: Number },
        steps:     { type: Number },
        x:     { type: Number },
        y:     { type: Number },
        z:     { type: Number },
        time: { type: String }
        /**name:   { type: String },
        area:   { type: String },
        format: { type: String },
        type:   { type: String },
        category: { type: String },
        gender: { type: String },
        divisionLevel: { type: Number },*/
    },{
        toJSON: {
            transform: function(doc, ret, options) {
                delete ret._id;
                delete ret.__v;
                return ret;
            }
        }
    });

trackdataSchema.static('findById', function(id) { return this.findOne({cardId:id}); });
trackdataSchema.static('removeById', function(id) { return this.remove({id}); });
trackdataSchema.static('upsert', function(id, Data) {
    return this.findOneAndUpdate({id}, Data, { new:true, upsert: true })
});

module.exports = model('trackdatas', trackdataSchema);